<?php
    
    namespace App\Observers;
    
    use App\Jobs\SendMsg;
    use App\System\Base\Services\SmsService;
    use App\System\Cis\Model\CisUser;
    use App\System\Log\Repositories\LogAdminRepository;

    class CisUserObserver
    {
        protected $oldUser;
        /**
         * 监听用户更新的事件。
         *
         * @param  CisUser  $cisUser
         * @return void
         */
        public function updated(CisUser $cisUser)
        {
            $data['type'] = 1;
            $data['log_info'] = '修改用户信息';
            if($cisUser->isDirty('user_type') && $cisUser->user_type == 2){
                $data['log_info'] = '设置为城市合伙人';
                if($cisUser->mobile) (SmsService::getInstance())->sendMsg($cisUser->mobile,12,[]);//城为城市合伙人，发送短信
            }
            if($cisUser->isDirty(['status'])){
                $data['log_info'] = '修改创客帐号状态';
            }
            $logAdmin = LogAdminRepository::getInstance();
            $logAdmin->saveAdminLog($data);
        }
        
        /**
         * 监听用户删除事件。
         *
         * @param  CisUser  $cisUser
         * @return void
         */
        public function deleted(CisUser $cisUser)
        {

        }
    }
     
    